﻿using log4net;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using NETCORE.Log4NetToMysql.Pattern;

namespace NETCORE.Log4NetToMysql.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class ValuesController : ControllerBase
    {
        private readonly ILogger<ValuesController> LoggerValue;
        private readonly ILog LogValue;
        public ValuesController(ILogger<ValuesController> logger)
        {
            this.LoggerValue = logger;

            LogValue = LogManager.GetLogger("Values");
        }

        [HttpGet]
        public IActionResult Get()
        {
            try
            {
                LoggerValue.LogInformation($"{this.GetType()},info,接口访问");
                LoggerValue.LogError($"{this.GetType()},error,接口访问错误");

                var cpm = new ActionLoggerInfo() { event_name = "ccc" };

                LogValue.Info(cpm);

                return Ok();
            }
            catch (Exception ex)
            {
                return BadRequest(ex.Message);
            }
        }
    }
}
